/**
 * 
 */
package com.zhaoyan.cms.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zhaoyan.cms.pojo.Article;
import com.zhaoyan.cms.pojo.Category;
import com.zhaoyan.cms.pojo.Channel;
import com.zhaoyan.cms.pojo.Comment;
import com.zhaoyan.cms.pojo.Vote;
import com.zhaoyan.cms.pojo.vo.ArticleVo;
import com.zhaoyan.cms.pojo.vo.VoteVo;

/**
 * @author zhaoyan
 *
 * 2020年1月19日
 */
public interface ArticleMapper {

	/**热度的文章
	 * @return
	 */
	List<Article> hotList();

	/**最新的文章
	 * @param i
	 * @return
	 */
	List<Article> articleListByCreated(int i);

	/**
	 * @return
	 */
	@Select("SELECT * FROM cms_channel")
	List<Channel> findChannels();

	/**
	 * @param categoryId
	 * @param channelId
	 * @return
	 */
	List<Article> articleList(@Param("categoryId")Integer categoryId, @Param("channelId")Integer channelId);

	/**
	 * @param channelId
	 * @return
	 */
	@Select("SELECT id , name FROM cms_category WHERE channel_id = #{value}")
	List<Category> findCategoryList(Integer channelId);

	/**
	 * @param id
	 * @return
	 */
	List<Article> findArticles(Integer id);

	/**
	 * @param article
	 * @return
	 */
	Integer addArticle(Article article);

	/**
	 * @param id
	 * @return
	 */
	@Update("UPDATE cms_article SET deleted = 1 WHERE id = #{value}")
	Integer delOne(Integer id);

	/**
	 * @param id
	 * @return
	 */
	Article findArticle(Integer id);

	/**
	 * @param article
	 * @return
	 */
	Integer updateOne(Article article);

	/**
	 * @param vo
	 * @return
	 */
	List<Article> findArticleList(ArticleVo vo);

	/**
	 * @param id
	 * @param statusId
	 * @return
	 */
	@Update("UPDATE cms_article SET `status` = #{statusId} WHERE id = #{id}")
	Integer setStatus(@Param("id")Integer id, @Param("statusId")Integer statusId);

	/**
	 * @param id
	 * @param statusId
	 * @return
	 */
	@Update("UPDATE cms_article SET `hot` = #{statusId} WHERE id = #{id}")
	Integer setHot(Integer id, Integer statusId);

	/**
	 * @param userId
	 * @param lockedId
	 * @return
	 */
	@Update("UPDATE cms_user SET `locked` = #{lockedId} WHERE id = #{lockedId}")
	Integer setUser(@Param("userId")Integer userId, @Param("lockedId")Integer lockedId);

	/**
	 * @param articeId
	 * @return
	 */
	@Select("SELECT id,articleId,userId,content,created FROM cms_comment WHERE articleId = #{value} "
			+ " ORDER BY created DESC")
	List<Comment> findComment(Integer articeId);

	/**
	 * @param comment
	 * @return
	 */
	@Insert("INSERT INTO cms_comment(articleId,userId,content,created) "
			+ "VALUES(#{articleId},#{userId},#{content},now() )")
	Integer addComment(Comment comment);
	
	@Update("UPDATE cms_article SET commentCnt= commentCnt + 1 WHERE id = #{value}")
	Integer updateArticleCommentCount(Integer articeId);

	/**
	 * @param vote
	 * @return
	 */
	@Insert("INSERT INTO cms_article_vote VALUES(0,#{content},#{title})")
	Integer addVote(Vote vote);
	

}
